/**
 * @description 验收信息路由
 * @date 2020-08-21 14:03
 * @auth LI
 */

const router = require('koa-router')()
const {
  addAcceptanceInfo,
  acceptanceConfirm,
  getAcceptanceList,
  updateAcceptanceInfo
} = require('../../controller/acceptanceInfo')

router.prefix('/jihuide/acceptanceInfo')

// 添加验收信息
router.post('/addAcceptanceInfo', async (ctx, next) => {
  let { workerAccountId, houseInfoId, houseOwnerId, typeLevel, acceptancePhoto, acceptanceTime, remark } = ctx.request.body
  workerAccountId = parseInt(workerAccountId)
  houseInfoId = parseInt(houseInfoId)
  houseOwnerId = parseInt(houseOwnerId)
  // 接下来交给控制层
  ctx.body = await addAcceptanceInfo({
    workerAccountId,
    houseInfoId,
    houseOwnerId,
    typeLevel,
    acceptancePhoto,
    acceptanceTime,
    remark
  })
})

// 工人确认验收信息
router.post('/acceptanceConfirm', async (ctx, next) => {
  let { workerAccountId, houseInfoId, houseOwnerId, typeLevel, code } = ctx.request.body
  workerAccountId = parseInt(workerAccountId)
  houseInfoId = parseInt(houseInfoId)
  houseOwnerId = parseInt(houseOwnerId)
  code = Number(code)
  // 接下来交给控制层
  ctx.body = await acceptanceConfirm({
    workerAccountId,
    houseInfoId,
    houseOwnerId,
    typeLevel,
    code
  })
})

// 获取验收信息
router.post('/getAcceptanceList', async (ctx, next) => {
  let { workerAccountId, houseInfoId, typeLevel } = ctx.request.body
  workerAccountId = parseInt(workerAccountId)
  houseInfoId = parseInt(houseInfoId)
  // 接下来交给控制层
  ctx.body = await getAcceptanceList({
    workerAccountId,
    houseInfoId,
    typeLevel
  })
})

// 更新验收信息
router.post('/updateAcceptanceInfo', async (ctx, next) => {
  let { id, typeLevel, reserve } = ctx.request.body
  id = parseInt(id)
  console.log('+++ '+Boolean(id))
  // 接下来交给控制层
  ctx.body = await updateAcceptanceInfo({
    id,
    typeLevel,
    reserve
  })
})

module.exports = router
